home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / funkyjet.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  349 lines

  1. /***************************************************************************
  2.  
  3.    Funky Jet Video emulation - Bryan McPhail, mish@tendril.co.uk
  4.  
  5.    Cut & paste from Super Burgertime for now! :)
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. #define TILERAM_SIZE    0x2000
  13.  
  14. unsigned char *funkyjet_pf2_data,*funkyjet_pf1_data,*funkyjet_pf1_row;
  15. static unsigned char *funkyjet_pf1_dirty,*funkyjet_pf2_dirty;
  16. static struct osd_bitmap *funkyjet_pf1_bitmap;
  17. static struct osd_bitmap *funkyjet_pf2_bitmap;
  18.  
  19. static unsigned char funkyjet_control_0[16];
  20. static int offsetx[4],offsety[4];
  21.  
  22. /******************************************************************************/
  23.  
  24. static void funkyjet_update_palette(void)
  25. {
  26.     int offs,color,code,i,pal_base;
  27.     int colmask[16];
  28.     unsigned int *pen_usage;
  29.  
  30.     palette_init_used_colors();
  31.  
  32.     pen_usage=Machine->gfx[1]->pen_usage;
  33.     pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  34.     for (color = 0;color < 16;color++) colmask[color] = 0;
  35.     for (offs = 0; offs < TILERAM_SIZE;offs += 2)
  36.     {
  37.         code = READ_WORD(&funkyjet_pf2_data[offs]);
  38.         color = (code & 0xf000) >> 12;
  39.         code &= 0x0fff;
  40.         colmask[color] |= pen_usage[code];
  41.     }
  42.  
  43.     for (color = 0;color < 16;color++)
  44.     {
  45.         if (colmask[color] & (1 << 0))
  46.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  47.         for (i = 1;i < 16;i++)
  48.         {
  49.             if (colmask[color] & (1 << i))
  50.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  51.         }
  52.     }
  53.  
  54.     pen_usage=Machine->gfx[0]->pen_usage;
  55.     pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
  56.     for (color = 0;color < 16;color++) colmask[color] = 0;
  57.     for (offs = 0; offs < TILERAM_SIZE;offs += 2)
  58.     {
  59.         code = READ_WORD(&funkyjet_pf1_data[offs]);
  60.         color = (code & 0xf000) >> 12;
  61.         code &= 0x0fff;
  62.         colmask[color] |= pen_usage[code];
  63.     }
  64.  
  65.     for (color = 0;color < 16;color++)
  66.     {
  67.         if (colmask[color] & (1 << 0))
  68.             palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
  69.         for (i = 1;i < 16;i++)
  70.         {
  71.             if (colmask[color] & (1 << i))
  72.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  73.         }
  74.     }
  75.  
  76.     /* Sprites */
  77.     pen_usage=Machine->gfx[2]->pen_usage;
  78.     pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
  79.     for (color = 0;color < 16;color++) colmask[color] = 0;
  80.  
  81.     for (offs = 0;offs < 0x800;offs += 8)
  82.     {
  83.         int x,y,sprite,multi;
  84.  
  85.         sprite = READ_WORD (&spriteram[offs+2]) & 0x1fff;
  86.         if (!sprite) continue;
  87.  
  88.         y = READ_WORD(&spriteram[offs]);
  89.         x = READ_WORD(&spriteram[offs+4]);
  90.         color = (x >>9) &0xf;
  91.  
  92.         multi = (1 << ((y & 0x0600) >> 9)) - 1;    /* 1x, 2x, 4x, 8x height */
  93.  
  94.         sprite &= ~multi;
  95.  
  96.         while (multi >= 0)
  97.         {
  98.             colmask[color] |= pen_usage[(sprite + multi)&0x1fff];
  99.             multi--;
  100.         }
  101.     }
  102.  
  103.     for (color = 0;color < 16;color++)
  104.     {
  105.         for (i = 1;i < 16;i++)
  106.         {
  107.             if (colmask[color] & (1 << i))
  108.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  109.         }
  110.     }
  111.  
  112.     if (palette_recalc())
  113.     {
  114.         memset(funkyjet_pf2_dirty,1,TILERAM_SIZE);
  115.         memset(funkyjet_pf1_dirty,1,TILERAM_SIZE);
  116.     }
  117. }
  118.  
  119. static void funkyjet_drawsprites(struct osd_bitmap *bitmap)
  120. {
  121.     int offs;
  122.  
  123.     for (offs = 0;offs < 0x800;offs += 8)
  124.     {
  125.         int x,y,sprite,colour,multi,fx,fy,inc,flash;
  126.  
  127.         sprite = READ_WORD (&spriteram[offs+2]) & 0x1fff;
  128.         if (!sprite) continue;
  129.  
  130.         y = READ_WORD(&spriteram[offs]);
  131.         flash=y&0x1000;
  132.         if (flash && (cpu_getcurrentframe() & 1)) continue;
  133.  
  134.         x = READ_WORD(&spriteram[offs+4]);
  135.         colour = (x >>9) & 0xf;
  136.  
  137.         fx = y & 0x2000;
  138.         fy = y & 0x4000;
  139.         multi = (1 << ((y & 0x0600) >> 9)) - 1;    /* 1x, 2x, 4x, 8x height */
  140.  
  141.         x = x & 0x01ff;
  142.         y = y & 0x01ff;
  143.         if (x >= 320) x -= 512;
  144.         if (y >= 256) y -= 512;
  145.         y = 240 - y;
  146.         x = 304 - x;
  147.  
  148.         if (x>320) continue;
  149.  
  150.         sprite &= ~multi;
  151.         if (fy)
  152.             inc = -1;
  153.         else
  154.         {
  155.             sprite += multi;
  156.             inc = 1;
  157.         }
  158.  
  159.         while (multi >= 0)
  160.         {
  161.             drawgfx(bitmap,Machine->gfx[2],
  162.                     sprite - multi * inc,
  163.                     colour,
  164.                     fx,fy,
  165.                     x,y - 16 * multi,
  166.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  167.  
  168.             multi--;
  169.         }
  170.     }
  171. }
  172.  
  173. static void funkyjet_pf1_update(void)
  174. {
  175.     int offs,mx,my,color,tile;
  176.  
  177.     mx = -1;
  178.     my = 0;
  179.     for (offs = 0; offs < 0x2000 ;offs += 2)
  180.     {
  181.         mx++;
  182.         if (mx == 64)
  183.         {
  184.             mx = 0;
  185.             my++;
  186.         }
  187.  
  188.         if (funkyjet_pf1_dirty[offs])
  189.         {
  190.             funkyjet_pf1_dirty[offs] = 0;
  191.             tile = READ_WORD(&funkyjet_pf1_data[offs]);
  192.             color = (tile & 0xf000) >> 12;
  193.  
  194.             drawgfx(funkyjet_pf1_bitmap,Machine->uifont, //gfx[0],
  195.                     tile & 0x0fff,
  196.                     color,
  197.                     0,0,
  198.                     8*mx,8*my,
  199.                     0,TRANSPARENCY_NONE,0);
  200.         }
  201.     }
  202. }
  203.  
  204. static void funkyjet_pf2_update(void)
  205. {
  206.     int offs,mx,my,color,tile,quarter;
  207.  
  208.     for (quarter = 0;quarter < 4;quarter++)
  209.     {
  210.         mx = -1;
  211.         my = 0;
  212.  
  213.           for (offs = 0x400 * quarter; offs < 0x400 * quarter + 0x400;offs += 2)
  214.         {
  215.             mx++;
  216.             if (mx == 32)
  217.             {
  218.                 mx = 0;
  219.                 my++;
  220.             }
  221.  
  222.             if (funkyjet_pf2_dirty[offs])
  223.             {
  224.                 funkyjet_pf2_dirty[offs] = 0;
  225.                 tile = READ_WORD(&funkyjet_pf2_data[offs]);
  226.                 color = (tile & 0xf000) >> 12;
  227.  
  228.                 drawgfx(funkyjet_pf2_bitmap,Machine->gfx[1],
  229.                         tile & 0x0fff,
  230.                         color,
  231.                         0,0,
  232.                         16*mx + offsetx[quarter],16*my + offsety[quarter],
  233.                         0,TRANSPARENCY_NONE,0);
  234.             }
  235.         }
  236.     }
  237. }
  238.  
  239. /******************************************************************************/
  240.  
  241. void funkyjet_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  242. {
  243.     int scrollx,scrolly;
  244.  
  245.     funkyjet_update_palette();
  246.     funkyjet_pf1_update();
  247.     funkyjet_pf2_update();
  248.  
  249.     /* Background */
  250.     scrollx=-READ_WORD (&funkyjet_control_0[6]);
  251.     scrolly=-READ_WORD (&funkyjet_control_0[8]);
  252.      copyscrollbitmap(bitmap,funkyjet_pf2_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  253.  
  254.     /* Sprites */
  255. //    funkyjet_drawsprites(bitmap);
  256.  
  257.     /* Foreground */
  258.     scrollx=-READ_WORD (&funkyjet_control_0[2]);
  259.     scrolly=-READ_WORD (&funkyjet_control_0[4]);
  260.  
  261.     /* 'Fake' rowscroll, used only in the end game message */
  262.     if (READ_WORD (&funkyjet_control_0[0xc])==0xc0)
  263.         scrollx=-READ_WORD (&funkyjet_pf1_row[8]);
  264.     copyscrollbitmap(bitmap,funkyjet_pf1_bitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_PEN,palette_transparent_pen);
  265.  
  266.     funkyjet_drawsprites(bitmap);
  267. }
  268.  
  269. /******************************************************************************/
  270.  
  271. WRITE_HANDLER( funkyjet_pf2_data_w )
  272. {
  273.     int oldword = READ_WORD(&funkyjet_pf2_data[offset]);
  274.     int newword = COMBINE_WORD(oldword,data);
  275.  
  276.     if (oldword != newword)
  277.     {
  278.         WRITE_WORD(&funkyjet_pf2_data[offset],newword);
  279.         funkyjet_pf2_dirty[offset] = 1;
  280.     }
  281. }
  282.  
  283. WRITE_HANDLER( funkyjet_pf1_data_w )
  284. {
  285.     int oldword = READ_WORD(&funkyjet_pf1_data[offset]);
  286.     int newword = COMBINE_WORD(oldword,data);
  287.  
  288.     if (oldword != newword)
  289.     {
  290.         WRITE_WORD(&funkyjet_pf1_data[offset],newword);
  291.         funkyjet_pf1_dirty[offset] = 1;
  292.     }
  293. }
  294.  
  295. READ_HANDLER( funkyjet_pf1_data_r )
  296. {
  297.     return READ_WORD(&funkyjet_pf1_data[offset]);
  298. }
  299.  
  300. READ_HANDLER( funkyjet_pf2_data_r )
  301. {
  302.     return READ_WORD(&funkyjet_pf2_data[offset]);
  303. }
  304.  
  305. WRITE_HANDLER( funkyjet_control_0_w )
  306. {
  307.     COMBINE_WORD_MEM(&funkyjet_control_0[offset],data);
  308. }
  309.  
  310. /******************************************************************************/
  311.  
  312. void funkyjet_vh_stop (void)
  313. {
  314.     osd_free_bitmap(funkyjet_pf2_bitmap);
  315.     osd_free_bitmap(funkyjet_pf1_bitmap);
  316.     free(funkyjet_pf1_dirty);
  317.     free(funkyjet_pf2_dirty);
  318. }
  319.  
  320. int funkyjet_vh_start(void)
  321. {
  322.     /* Allocate bitmaps */
  323.     if ((funkyjet_pf1_bitmap = osd_create_bitmap(512,512)) == 0) {
  324.         funkyjet_vh_stop ();
  325.         return 1;
  326.     }
  327.  
  328.     if ((funkyjet_pf2_bitmap = osd_create_bitmap(1024,512)) == 0) {
  329.         funkyjet_vh_stop ();
  330.         return 1;
  331.     }
  332.  
  333.     funkyjet_pf1_dirty = malloc(TILERAM_SIZE);
  334.     funkyjet_pf2_dirty = malloc(TILERAM_SIZE);
  335.     memset(funkyjet_pf2_dirty,1,TILERAM_SIZE);
  336.     memset(funkyjet_pf1_dirty,1,TILERAM_SIZE);
  337.  
  338.     offsetx[0] = 0;
  339.     offsetx[1] = 0;
  340.     offsetx[2] = 512;
  341.     offsetx[3] = 512;
  342.     offsety[0] = 0;
  343.     offsety[1] = 256;
  344.     offsety[2] = 0;
  345.     offsety[3] = 256;
  346.  
  347.     return 0;
  348. }
  349.